<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>用户登陆成功</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="css/plugins/clockpicker/clockpicker.css" rel="stylesheet">  
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">  
  </head>
  <body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>礼券领取记录</h5>
                </div>
                <div class="ibox-content">
                    <form role="form" id="custGiftRecordQueryForm" class="form-inline" action="custGiftRecord/listPageCustGiftRecord" method="post">
                        
                        <div class="form-group">
                            <input id="mobile" name="mobile" class="form-control" type="text" placeholder="请输入手机">
                        </div>
                        <div class="form-group" style="position:relative">
	                            <input id="startTime" name="startTime" class="form-control" type="text" readonly placeholder="点击激活开始时间">
	                            <p style="position: absolute;top:-16px;left: -8px;overflow: visible;word-wrap: normal;white-space: nowrap;color: rgba(204, 172, 55, 0.7);">（默认导出自当前日期向后推一个月的数据）</p>
	                    </div>  
	                    <div class="form-group" style="position:relative">
	                            <input id="endTime" name="endTime" class="form-control" type="text" readonly placeholder="点击激活结束时间">
	                            <p id="errTime" style="position: absolute;overflow: visible;word-wrap: normal;white-space: nowrap;color: #ff0000;"></p>
	                    </div>
                        <div class="input-group">
                            <button class="btn btn-primary" type="button" style="margin-bottom: 0px;"
                                    onclick="search();"><i class="fa fa-search"></i>&nbsp;查询
                            </button>
                        </div>
                        <div class="input-group">
	                            <button class="btn btn-primary" type="button" style="margin-bottom: 0px;"
	                                    onclick="exportExcel();"><i class="fa fa-search"></i>&nbsp;导出
	                            </button>
	                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- Panel Other -->
    <div class="ibox float-e-margins" id="tableShow">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <table id="custGiftRecordListTable" data-mobile-responsive="true"
                               data-click-to-select="true" data-unique-id="id">
                            <thead>
                            </thead>
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->
            </div>
        </div>
    </div>
</div>


<!-- End Panel Other -->
</div>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--下拉框-->
<script src="js/plugins/chosen/chosen.jquery.js"></script>
<!--时间选择-->
<script src="js/plugins/layer/laydate/laydate.js"></script>

<script>
var startTime = null;
var endTime = null;
//日期选择框
var start = {
	elem : "#startTime",
	format : "YYYY-MM-DD",
	max : "2099-06-16",
	istime : true,
	istoday : false,
	choose:function(date) {
		startTime = date;
	}
};
var end = {
	elem : "#endTime",
	format : "YYYY-MM-DD",
	max : "2099-06-16",
	istime : true,
	istoday : false,
	choose:function(date) {
		endTime = date;
	}
};
laydate(start);
laydate(end);

    var $table = $('#custGiftRecordListTable');

    var search = function () {
        $table.bootstrapTable('refresh');
    }
    
    var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };

    $(document).ready(function () {
        //将表单元素和table属性转成json
        queryParams = function (params) {
            var temp = {};
            temp.currentResult = params.offset;
            temp.showCount = params.limit;
            var formParam = $('#custGiftRecordQueryForm').serializeArray();
            for (var i = 0; i < formParam.length; i++) {
                if (formParam[i].value != '') {
                    temp[formParam[i].name] = formParam[i].value;
                }
            }
            return temp;
        };

        rowStyle = function (row, index) {
            var classes = ['active', 'success', 'info', 'warning', 'danger'];
            if (index % 2 === 0 && index / 2 < classes.length) {
                return {
                    classes: classes[index / 2]
                };
            }
            return {};
        }

        $table.bootstrapTable({
            url: "custGiftRecord/listPageCustGiftRecord",
            pagination: !0,
            showRefresh: !0,
            showToggle: !0,
            showColumns: !0,
            iconSize: "outline",
            striped: true, //是否显示行间隔色
            queryParams: queryParams,//传递参数（*）
            sidePagination: "server", //服务端处理分页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [5, 10, 20, 50],        //可供选择的每页的行数（*）
            minimunCountColumns: 2,      //可供选择的每页的行数（*）
            //detailView: true,
            sortName: undefined,
            sortOrder: 'asc',
            sortStable: false,
            type: "post",
            contentType: "application/json; charset=utf-8",
            rowStyle: rowStyle,
            iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
            icons: {
                refresh: "glyphicon-repeat",
                toggle: "glyphicon-list-alt",
                columns: "glyphicon-list",
                detailOpen: 'glyphicon-plus icon-plus',
                detailClose: 'glyphicon-minus icon-minus',
                sortable: 'glyphicon-minus icon-minus'
            },
            onLoadSuccess: function (data) {
                if (data.total < 5) {
                    $table.bootstrapTable('getOptions')["height"] = 400;
                } else {
                    $table.bootstrapTable('getOptions')["height"] = '';
                }

                $table.bootstrapTable('hideColumn', 'id');
                $table.bootstrapTable('hideColumn', 'edit');
            },
            columns: [{
	                title: '姓名',
	                field: 'name',
	                align: 'center',
	                valign: 'middle'
            	},{
                    title: '手机号码',
                    field: 'mobile',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '奖品类型',
                    field: 'prizeType',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                    	if(row.prizeType == "coupon"){
                    		return "门店券";
                    	} else if(row.prizeType == "point"){
                    		return "积分";
                    	} else if(row.prizeType == "product"){
                    		return "实物";
                    	}
                    }
                },{
                    title: '奖品名称',
                    field: 'goodsName',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '领取时间',
                    field: 'getDate',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        return CovertToDate(value);
                    }
                },{
                    title: '活动类型',
                    field: 'activityName',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '详细地址',
                    field: 'address',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                    		if(row.province == null && row.city == null && row.district == null && row.detailAddress == null) {
                    			return "-";
                    		} else {
                    			return row.province+row.city+row.district+row.detailAddress;
                    		}
                    }
                }
            ]
        });
        for (var selector in config)$(selector).chosen(config[selector]);
    });

    function tableHeight() {
        return $(window).height() - 50;
    }
    var exportExcel = function() {
    	var mobile = $("#mobile").val();
    	var startTime = $("#startTime").val();
    	var endTime = $("#endTime").val();
    	if(startTime==null || startTime==''&&endTime==null || endTime==''){
    	}else{
    		var days = datedifference(startTime,endTime);
    		if(days>=31){
    			 //$("#errTime").html("时间范围请控制在一个月内"); 
    			 alert("时间范围请控制在一个月内");
    			 return false;
    		}
    	}	
    	window.location.href = "custGiftRecord/exportCustGiftRecord?mobile="+mobile+"&startTime="+startTime+"&endTime="+endTime; 
    }
    function datedifference(sDate1, sDate2){
    	var dateSpan,
        tempDate,
        iDays;
        sDate1 = Date.parse(sDate1);
        sDate2 = Date.parse(sDate2);
        dateSpan = sDate2 - sDate1;
        dateSpan = Math.abs(dateSpan);
        iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
        return iDays
    }
    function CovertToDate(unittime) {
        //3.转换成js时间格式
        var jsDate = new Date(unittime).Format("yyyy-MM-dd hh:mm:ss");
     	
        return jsDate;


    }
    Date.prototype.Format = function (fmt) { //author: meizz 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
</script>
  </body>
</html>
